package com.night.administration.controller;

import com.night.administration.excepyion.AreaConflictException;
import com.night.administration.excepyion.TeacherTimeConflictException;
import com.night.administration.service.TestService;
import com.night.common.entity.ResultVo;
import com.night.common.entity.administration.Test;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @ClassName: TeacherController
 * @Description: //TODO
 * @author: LZJ
 * @date: 2022/10/23-14:15
 * @version: v1.0
 */
@RestController
@RequestMapping("/api/v1/test")
public class TestController {
    @Resource
    private TestService testService;

    @PostMapping("/list")

    public ResultVo<Test> getAllByCondition(@RequestBody Test test) {
        return new ResultVo(testService.getByCondition(test));
    }
    @PostMapping("/add")
    public ResultVo<String> add(@RequestBody Test test) {
        try {
            testService.insert(test);
        } catch (AreaConflictException e) {
            e.printStackTrace();
        } catch (TeacherTimeConflictException e) {
            e.printStackTrace();
        }
        return ResultVo.SUCCESS;
    }

    @PostMapping("/update")
    public ResultVo<String> update(@RequestBody Test test) {
        testService.update(test);
        return ResultVo.SUCCESS;
    }

}
